﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;

namespace ZhangZhao.WebAPI
{
    public partial class UserContactEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string s = Output.Fail;

            try
            {
                //string DataValue = HttpUtility.HtmlEncode(HttpContext.Current.Request[Parameter.JsonData]);
                string Command = HttpUtility.HtmlEncode(HttpContext.Current.Request[Parameter.Command]);

                string UserName = HttpContext.Current.Request["UserName"];
                string Email = HttpContext.Current.Request["Email"];
                string Phone1 = HttpContext.Current.Request["Phone1"];
                string Phone2 = HttpContext.Current.Request["Phone2"];
                string WeiBo = HttpContext.Current.Request["WeiBo"];
                string WeiXin = HttpContext.Current.Request["WeiXin"];
                string QQ = HttpContext.Current.Request["QQ"];
                string Website = HttpContext.Current.Request["Website"];
                string HomeAddress = HttpContext.Current.Request["HomeAddress"];
                string Province = HttpContext.Current.Request["Province"];
                string City = HttpContext.Current.Request["City"];
                string District = HttpContext.Current.Request["District"];

                int UserContactId; int.TryParse(HttpContext.Current.Request["UserContactId"], out UserContactId);


                if (!string.IsNullOrWhiteSpace(Command))
                {
                    ZhangZhao.BLL.H_UserContact bll = new ZhangZhao.BLL.H_UserContact();

                    if (Command.Equals(CommandParameterValue.Add, StringComparison.CurrentCultureIgnoreCase))
                    {
                        //添加联系信息
                        if (!string.IsNullOrWhiteSpace(Command) && Command.Equals(CommandParameterValue.Add, StringComparison.CurrentCultureIgnoreCase))
                        {
                            bll.Add(new ZhangZhao.Model.H_UserContact()
                            {
                                City = City,
                                District = District,
                                Email = Email,
                                HomeAddress = HomeAddress,
                                Phone1 = Phone1,
                                Phone2 = Phone2,
                                Province = Province,
                                QQ = QQ,
                                UserName = UserName,
                                Website = Website,
                                WeiBo = WeiBo,
                                WeiXin = WeiXin
                            });
                            s = Output.Success;
                        }

                        //删除联系信息
                        if (Command.Equals(CommandParameterValue.Delete, StringComparison.CurrentCultureIgnoreCase))
                        {
                            if (UserContactId > 0)
                            {
                                bll.Delete(UserContactId);
                                s = Output.Success;
                            }
                        }
                        //修改联系信息
                        if (Command.Equals(CommandParameterValue.Update, StringComparison.CurrentCultureIgnoreCase))
                        {
                            if (UserContactId > 0)
                            {
                                bll.Update(new ZhangZhao.Model.H_UserContact()
                                {
                                    City = City,
                                    District = District,
                                    Email = Email,
                                    HomeAddress = HomeAddress,
                                    Phone1 = Phone1,
                                    Phone2 = Phone2,
                                    Province = Province,
                                    QQ = QQ,
                                    UserName = UserName,
                                    Website = Website,
                                    WeiBo = WeiBo,
                                    WeiXin = WeiXin,
                                    Id = UserContactId
                                });
                                s = Output.Success;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                s = Output.Exception + ":" + ex.Message;
            }

            Response.Clear();
            Response.Write(s);
            Response.End();
        }
    }
}